mvn -version
rootpath=`pwd`
echo root path $rootpath
# 根据pom版本号，去除横线后，作为构建tag
export pom=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo pom version: $pom

export VERSION=$(echo $pom | awk -F '-SNAPSHOT' '{print $1}')
echo version: $VERSION
echo git branch: $CI_COMMIT_REF_NAME

if echo "${CI_COMMIT_REF_NAME}" | grep -q "^release/"; then
   echo "构建正式版";
else
   echo "构建开发版";
   VERSION=$(echo $CI_COMMIT_REF_NAME  | tr / _)-${VERSION}
   pom=${VERSION}-SNAPSHOT
fi

echo call version $VERSION

wget -O tag "http://devops.flashhold.com:8000/get_gitlab_tag_name?branch_name=&gitlab_project_id=${CI_PROJECT_ID}&ci_pipeline_id=${CI_PIPELINE_ID}&version=${VERSION}"
export TAG=`cat tag`
export TAG=${VERSION}${TAG}

echo final tag $TAG

CATEGORY=${TAG%-*}
echo maven build with pom $pom
# 需要重新编译一次， 将application模块生成出标准jar，供定制开发使用
cd ${rootpath}
#mvn -Drevision=$pom clean deploy -T 2C -Dmaven.test.skip=true -U -Pdev
mvn -Drevision=$pom -Ddocker.image.tag=${TAG} -Dbranch.slug=${CI_COMMIT_REF_SLUG} clean install -T 2C -Dmaven.test.skip=true -U -Pbuild,x64

jar_file=`find ./ -name ${APP}.jar -print`
echo exec jar: $jar_file

#dockerfile=`find ./ -name Dockerfile -print`
#sed -i 's|harbor2.flashhold.com/kc-evo/||g' ${dockerfile}
#mkdir -p ${APP}:${TAG}/target
#echo "docker build -t ${APP}:${TAG} ./" > ${APP}:${TAG}/build.sh
#cp ${jar_file} ${APP}:${TAG}/target
#cp ${dockerfile} ${APP}:${TAG}
## cp ${dockerfile} ${start_rcs_sh} ${wait_for_sh} ${entrypoint_sh} ${APP}:${TAG}
#chmod u+x ${APP}:${TAG}/build.sh
## chmod 755 ${APP}:${TAG}/start-rcs.sh ${APP}:${TAG}/wait-for.sh ${APP}:${TAG}/entrypoint.sh
#mkdir -p ${APP}:${TAG}/ops
##cp -r ./target/ops ${APP}:${TAG}/
#tar -czf ${APP}:${TAG}.tar.gz ${APP}:${TAG}/*
#ssh -o StrictHostKeyChecking=no softoutfile.flashhold.com "mkdir -p /var/www/html/evo/${COMPANY}/${APP}/${CATEGORY}"
#scp -o StrictHostKeyChecking=no ./${APP}:${TAG}.tar.gz softoutfile.flashhold.com:/var/www/html/evo/${COMPANY}/${APP}/${CATEGORY}
#wget "http://devops.flashhold.com:8000/push_image_version?image_name=${APP}:${TAG}&project_name=${COMPANY}&app_name=${APP}&branch_name=${CI_COMMIT_REF_SLUG}&repo_address=harbor2.flashhold.com/$COMPANY/$APP:$TAG&chart_address=http://harbor2.flashhold.com/chartrepo/$COMPANY/${APP}&domain=${COMPANY}-${APP}.k8s.flashhold.com&container_port=${CONTAINERPORT}&service_port=${SERVICEPORT}&chart_version=${CHART_VERSION}&baseapp_flag=${BASEAPP_FLAG}&http=1"
#wget -q "http://devops.flashhold.com:8000/set_app_tag?tag_name=${TAG}&gitlab_project_id=${CI_PROJECT_ID}&branch_name=${CI_COMMIT_REF_NAME}&ci_pipeline_id=${CI_PIPELINE_ID}"
#docker login -u "${REGISTRY_USERNAME}" -p "${REGISTRY_PASSWORD}" harbor2.flashhold.com
## 有的需要改
# docker pull harbor2.flashhold.com/kc-evo/java8:latest
# docker tag harbor2.flashhold.com/kc-evo/java8:latest java8:latest
#cd ${APP}:${TAG}
#pwd
#ls -a .
#ls ./target
#docker build -t harbor2.flashhold.com/${COMPANY}/${APP}:${TAG} ./
#docker push harbor2.flashhold.com/${COMPANY}/${APP}:${TAG}

cd ${rootpath}
echo root path $rootpath
ls ${rootpath}
ssh -o StrictHostKeyChecking=no softoutfile.flashhold.com "mkdir -p /var/www/html/evo/graybox-device/${CATEGORY}/${TAG}"
tar -czvf ${APP}-${TAG}.tar.gz -C ./${APP}/target --exclude='classes' --exclude='maven-archiver' --exclude='generated-sources' --exclude='maven-status' .
scp -o StrictHostKeyChecking=no ${APP}-${TAG}.tar.gz softoutfile.flashhold.com:/var/www/html/evo/graybox-device/${CATEGORY}/${TAG}
wget "http://devops.flashhold.com:8000/push_image_version?image_name=${APP}:${TAG}&project_name=${COMPANY}&app_name=${APP}&branch_name=${CI_COMMIT_REF_SLUG}&repo_address=harbor2.flashhold.com/$COMPANY/$APP:$TAG&chart_address=http://harbor2.flashhold.com/chartrepo/$COMPANY/${APP}&domain=${COMPANY}-${APP}.k8s.flashhold.com&container_port=${CONTAINERPORT}&service_port=${SERVICEPORT}&chart_version=${CHART_VERSION}&baseapp_flag=${BASEAPP_FLAG}&http=1"
wget -q "http://devops.flashhold.com:8000/set_app_tag?tag_name=${TAG}&gitlab_project_id=${CI_PROJECT_ID}&branch_name=${CI_COMMIT_REF_NAME}&ci_pipeline_id=${CI_PIPELINE_ID}"

